cmake_minimum_required (VERSION 3.12.2...3.13.2)
project (list_test)

message (">>> in list_test project")

cmake_policy (GET CMP0108 cmp_0108)
message (">>> cmp0108 = ${cmp_0108}")

cmake_policy (GET CMP0081 cmp_0081)
message (">>> cmp0081 = ${cmp_0081}")

set (list_test a b c d)
message (">>> list_test = ${list_test}")

message ("")
message ("------test reading subcommands-----------")
list (LENGTH list_test len) # 中间的list变量不需要加${}
message (">>> LENGTH: ${len}")

list (GET list_test 0 1 -1 -2 list_new)
message (">>> GET: ${list_new}")

list (JOIN list_test "-G-" list_join)
message (">>> JOIN: ${list_join}")

list (SUBLIST list_test 1 2 list_new)
message (">>> SUBLIST: ${list_new}")
list (SUBLIST list_test 1 0 list_new)
message (">>> SUBLIST: ${list_new}")
list (SUBLIST list_test 1 -1 list_new)
message (">>> SUBLIST: ${list_new}")
list (SUBLIST list_test 1 8 list_new)
message (">>> SUBLIST: ${list_new}")

list (SUBLIST list_test 1 3 list_sub)
message (">>> SUBLIST: ${list_sub}")
message ("------test reading subcommands END-----------")
message ("")
message ("------test search subcommands-----------")
list (FIND list_test d list_find_index)
message (">>> FIND 'd': ${list_find_index}")
list (FIND list_test e list_find_index)
message (">>> FIND 'e': ${list_find_index}")
message ("------test search subcommands END-----------")

message ("")
message ("------test modification subcommands-----------")
list (APPEND list_test 1 2 3 4)
message (">>> APPEND: ${list_test}")
list (FILTER list_test INCLUDE REGEX [a-z])
message (">>> FILTER: ${list_test}")
list (FILTER list_test EXCLUDE REGEX [a-z])
message (">>> FILTER: ${list_test}")

set (list_test a b c d)
list (INSERT list_test 0 8 8 8 8)
message (">>> INSERT: ${list_test}")
list (INSERT list_test -1 9 9 9 9)
message (">>> INSERT: ${list_test}")
list (LENGTH list_test length)
list (INSERT list_test ${length} 0)
message (">>> INSERT: ${list_test}")

set (list_test a b c d)
list (POP_BACK list_test)
message (">>> POP_BACK: ${list_test}") # 未指定最后的参数，则移除最后一个元素
list (POP_BACK list_test outvar1 outvar2 outvar3 outvar4)
message (">>> POP_BACK:${outvar1}-${outvar2}-${outvar3}-${outvar4}") # 依次移除列表中的字后一个元素赋值给变量，并从原列表中移除该元素
set (list_test a b c d)
list (POP_FRONT list_test)
message (">>> POP_FRONT: ${list_test}") # 未指定最后的参数，则移除最后一个元素
list (POP_FRONT list_test outvar1 outvar2 outvar3 outvar4)
message (">>> POP_FRONT:${outvar1}-${outvar2}-${outvar3}-${outvar4}") # 依次移除列表中的字后一个元素赋值给变量，并从原列表中移除该元素


list (POP_FRONT list_test)
message (">>> POP_FRONT: ${list_test}")
list (POP_FRONT list_test outvar1 outvar2 outvar3)
message (">>> POP_FRONT: ${list_test} ${outvar1} ${outvar2} ${outvar3}") # 依次移除列表中的字第一个元素赋值给变量，并从原列表中移除该元素

set (list_test a b c d)
list (PREPEND list_test z)
message (">>> PREPEND: ${list_test}")
list (PREPEND list_test p q r s t)
message (">>> PREPEND: ${list_test}") # 将变量插入到第一个元素前

set (list_test a a b c c d)
list (REMOVE_ITEM list_test a)
message (">>> REMOVE_ITEM: ${list_test}")
list (REMOVE_ITEM list_test b e c d g h)
message (">>> REMOVE_ITEM: ${list_test}")

set (list_test a b c d e f)
list (REMOVE_AT list_test 0 -1)
message (">>> REMOVE_AT: ${list_test}")
list (REMOVE_AT list_test 1 1 1 1)
message (">>> REMOVE_AT: ${list_test}")

list (APPEND list_test q w e r t q w r r i r p)
message (">>> APPEND: ${list_test}")
list (REMOVE_DUPLICATES list_test)
message (">>> REMOVE_DUPLICATES: ${list_test}")

set (list_test a a a b b b c c c d d d) # 创建列表变量"a;a;a;b;b;b;c;c;c;d;d;d;"
list (REMOVE_DUPLICATES list_test)
message (">>> REMOVE_DUPLICATES: ${list_test}")
set (list_test a a a a) 
list (REMOVE_DUPLICATES list_test)
message (">>> REMOVE_DUPLICATES: ${list_test}")
set (list_test a b c a d a e a f) 
list (REMOVE_DUPLICATES list_test)
message (">>> REMOVE_DUPLICATES: ${list_test}")

set (list_test a b c d)
list (TRANSFORM list_test APPEND B OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test APPEND B)
message (">>> TRANSFORM-APPEND: ${list_test} --- ${list_test_out}")
set (list_test a b c d)
list (TRANSFORM list_test PREPEND F OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test PREPEND F)
message (">>> TRANSFORM-PREPEND: ${list_test} --- ${list_test_out}")

set (list_test a bb c d)
list (TRANSFORM list_test TOUPPER OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test TOUPPER)
message (">>> TRANSFORM-TOUPPER: ${list_test} --- ${list_test_out}")
set (list_test A B C DD)
list (TRANSFORM list_test TOLOWER OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test TOLOWER)
message (">>> TRANSFORM-TOLOWER: ${list_test} --- ${list_test_out}")

list (TRANSFORM list_test TOLOWER OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test TOLOWER)
message (">>> TRANSFORM-TOLOWER: ${list_test} *** ${list_test_out}")
list (TRANSFORM list_test TOUPPER OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test TOUPPER)
message (">>> TRANSFORM-TOUPPER: ${list_test} *** ${list_test_out}")

set (list_test " a b " "   bb   " "c e" d)
message (">>> TRANSFORM list: ${list_test}")
list (TRANSFORM list_test STRIP OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test STRIP)
message (">>> TRANSFORM-STRIP: ${list_test} --- ${list_test_out}")

set (list_test a b c d $<STREQUAL:"a","a"> $<STREQUAL:"a","b">)
list (LENGTH list_test len)
message (">>> TRANSFORM list: ${list_test}, len = ${len}")
list (TRANSFORM list_test GENEX_STRIP OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test GENEX_STRIP)
list (LENGTH list_test len_new)
message (">>> TRANSFORM-STRIP: ${list_test} --- ${list_test_out}, new len = ${len_new}")

set (list_test aa bb cc dd 1a b2 33 44)
message (">>> TRANSFORM-list: ${list_test}")
list (TRANSFORM list_test REPLACE "[a-c]" 9)
message (">>> TRANSFORM-REPLACE: ${list_test}")

set (list_test a b c d)
message (">>> TRANSFORM-list: ${list_test}")
list (TRANSFORM list_test APPEND Q AT 1 2 OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test APPEND Q AT 1 2)
message (">>> TRANSFORM-REPLACE: ${list_test} --- ${list_test_out}")

set (list_test a b c d e f g h i j k)
message (">>> TRANSFORM-list: ${list_test}")
list (TRANSFORM list_test APPEND Q FOR 0 -1 2 OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test APPEND Q FOR 0 -1 2)
message (">>> TRANSFORM-REPLACE: ${list_test} --- ${list_test_out}")

set (list_test a b c d e f g h i j k)
message (">>> TRANSFORM-list: ${list_test}")
list (TRANSFORM list_test APPEND Q REGEX "[a-f]" OUTPUT_VARIABLE list_test_out)
list (TRANSFORM list_test APPEND Q REGEX "[a-f]")
message (">>> TRANSFORM-REGEX: ${list_test} --- ${list_test_out}")

message ("------test modification subcommands END-----------")

message ("")
message ("------test order subcommands-----------")
set (list_test aa bb cc dd) 
message (">>> list: ${list_test}")
list (REVERSE list_test)
message (">>> REVERSE: ${list_test}")

set (list_test 3 1 1.1 10.1 3.4 9)
list (SORT list_test) # 以字母顺序，按照大小写不敏感方式，升序排列
message (">>> SORT STRING-SENSITIVE-ASCENDING: ${list_test}")
list (SORT list_test COMPARE NATURAL ORDER DESCENDING) # 以自然顺序，降序排列
message (">>> SORT STRING-SENSITIVE-DESCENDING: ${list_test}")

set (pathname "/test/a/filea/" "/test/a/fileA/")
list (SORT pathname COMPARE FILE_BASENAME CASE INSENSITIVE) 
message (">> pathnames sort: ${pathname}")


message ("------test order subcommands END-----------")

